<?php


namespace api\controllers;


use api\components\BaseController;
use common\helpers\commonApi;
use common\models\Campus;
use common\models\Carousel;
use Yii;

class HomeController extends BaseController
{
    /**
     * 轮播图
     * @return array
     */
    public function actionCarousel()
    {
        $data = Carousel::find()
            ->where(['status'=>1])
            ->select(['id as c_id','img','path'])
            ->orderBy(['sort'=>SORT_DESC,'create_time'=>SORT_DESC])
            ->asArray()->all();
        foreach ($data as &$datum){
            $datum['img'] = commonApi::getDomain($datum['img']);
        }
        return commonApi::message('ok',true,$data);
    }

    /**
     * 定位校区
     * @return array
     */
    public function actionLocate()
    {
        $get = Yii::$app->request->get();
        $long = $get['long']??'';
        $lat = $get['lat']??'';
        if (!$long||!$lat){
            return commonApi::message('请授权地址',false);
        }
        $model = new Campus();
        return $model->getUser($long,$lat);
    }

    /**
     * 校区列表
     * @return array
     */
    public function actionCampus()
    {
        $get = Yii::$app->request->get();
        $long = $get['long']??'';
        $lat = $get['lat']??'';
        if (!$long||!$lat){
            return commonApi::message('请授权地址',false);
        }
        $model = new Campus();
        return $model->getList($long,$lat);
    }
}